﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HyperionS2P
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            BindScannerList();
        }

        private void BindScannerList()
        {
            CbxScanner.DataSource = WIAScanner.GetDevices();
            CbxScanner.DisplayMember = "ScannerName";
            CbxScanner.ValueMember = "ScannerID";
        }

        private DocumentPDF CurrentDocument = null;

        private void BtnStartContinue_Click(object sender, EventArgs e)
        {
            if (CurrentDocument == null)
            {
                BtnStartContinue.Text = "Continue";
                TxtFolder.ReadOnly = true;
                //CurrentDocument = new DocumentPDF(TxtFolder.Text);
                CurrentDocument = new DocumentPDF();
            }

            Scanner scanner = CbxScanner.SelectedItem as Scanner;
            string destinationFolder = TxtFolder.Text;
            if (scanner != null)
            {
                List<Image> images = WIAScanner.Scan(scanner.ScannerID);
                foreach (Image image in images)
                {
                    CurrentDocument.AddImage(image);
                }
            }
        }

        private void BtnChooseFolder_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TxtFolder.Text = dialog.FileName;
            }
        }

        private void BtnFinishDocument_Click(object sender, EventArgs e)
        {
            BtnStartContinue.Text = "Start scanning";
            TxtFolder.ReadOnly = false;
            CurrentDocument.Save(TxtFolder.Text);
           // CurrentDocument.Save();
            CurrentDocument = null;
        }


    }
}
